/*
 * datastructure.cpp
 *
 *  Created on: 2009. 5. 12
 *      Author: neogeo94
 */

#include "datastructure.h"

CVertex::CVertex() {
	x=0;
	y=0;
	z=0;
	next=NULL;

}

CVertex::~CVertex() {

}

//------------------------------------------------------------------

CPolyline::CPolyline() {
	type=0;
	next=NULL;

	Vertexs=NULL;
	vertexCount=0;

}

CPolyline::~CPolyline() {
	CVertex* temp;
	while (Vertexs!=NULL)
	{
		temp=Vertexs->next;
		delete Vertexs;
		vertexCount--;
		Vertexs=temp;
	}

}

int CPolyline::AddVertex() {
	CVertex* temp;

	temp=Vertexs;
	Vertexs=new CVertex();
	Vertexs->next=temp;
	vertexCount++;
	return 0;

}

int CPolyline::AddVertex(double xx, double yy) {
	CVertex* temp;

	temp=Vertexs;
	Vertexs=new CVertex();
	Vertexs->next=temp;
	vertexCount++;

	Vertexs->x=xx;
	Vertexs->y=yy;

	return 0;

}

int CPolyline::CheckType() {
	CVertex* First;
	CVertex* Last;
	CVertex* temp;

	Last=First=temp=NULL;

	Last=temp=Vertexs;

	while(temp!=NULL){
		First=temp;
		temp=temp->next;
	}

	if (((First->x==Last->x)&&(First->y==Last->y))&&(vertexCount>2)) {
		type=1;
		///*debug*/std::cout<<"Closed Polygon!!!"<<std::endl;
	}

	///*debug*/std::cout<<"The number of vertexs: "<<vertexCount<<std::endl;

	return type;
}

//------------------------------------------------------------------

CEntities::CEntities (){
	Polylines=NULL;
	polylineCount=0;
	cpolylineCount=0;

}

CEntities::~CEntities (){
	CPolyline* temp;
	while (Polylines!=NULL)
	{
		temp=Polylines->next;
		delete Polylines;
		polylineCount--;
		Polylines=temp;
	}

}

int CEntities::AddPolyline() {
	CPolyline* temp;

	temp=Polylines;
	Polylines=new CPolyline();
	Polylines->next=temp;
	polylineCount++;
	return 0;
}

